<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%-- 使用taglib指令导入jstl标记 --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>   
<%@ page import="java.util.*" %> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>if标记和forEach标记</title>
</head>
<body>
<h3>1.if标记</h3>
<c:set var="age" value="14"></c:set>
<c:if test="${age >= 18}">
<div>年龄：${age},是成年人。</div>
</c:if>
<c:if test="${age < 18 }">
<div>年龄：${age},是未成年人。</div>
</c:if>

<c:set var = "num1">2</c:set>
<c:set var = "num2">5</c:set>
<c:if test="${num1 > num2 }">
 <div>${num1 } 大于 ${num2 }</div>
</c:if>
<c:if test="${num1 <= num2 }">
<div>${num1 } 小于等于 ${num2 }</div>
</c:if>
<h3>2.forEach标记</h3>
<!-- 
	begin：开始的索引
	end:结束的索引
	step:步长（增幅）
	var:定义每次循环的变量
 -->
<c:forEach begin="1" end="10" step="2" var="i">
   <div>${i}</div>
</c:forEach>


<!-- 模拟数据 -->
<%
	List<String> list = new ArrayList<String>();
	list.add("MySQL从入门到精通");
	list.add("30天学废Java");
	list.add("Spring自学之路");
	list.add("Spring自学之路1");
	list.add("Spring自学之路2");
	list.add("Spring自学之路3");	
	list.add("Spring自学之路4");	
	list.add("Spring自学之路5");	
	// 把数据放到页面当中
	pageContext.setAttribute("data",list);
	
	
	Map<String,String> map = new HashMap<String,String>(); 
	map.put("name", "zhangsan");
	map.put("age", "18");
	pageContext.setAttribute("map",map);
	
	
%>

<table border="1">
	<tr>
		<th>序号</th>
		<th>书籍名称</th>
	</tr>
	<!-- varStatus代表当前变量的状态,其中包含了index,count等属性 -->
	<c:forEach items="${data}" var="book" varStatus="status">
	<tr>
	    <!-- 获取索引 -->
		<td>${status.index+1}
		<td>${book}</td>
	</tr>
	</c:forEach>
	
	<!-- 对于Map集合，${item.key}用于获取键，${item.value}用于获取值 -->
	<c:forEach items="${map}" var="item">
		<div>键=${item.key}</div>
		<div>值=${item.value}</div>
	</c:forEach>
</table>



</body>
</html>